﻿//  main.cpp
//
//  Created by finalObject on 2020/7/29.
//  Copyright © 2020 finalObject. All rights reserved.
//

#include <iostream>

int getItemInFibonacciWithIndex(int index) {
	int result = 0;
	if (index == 0) 
	{
		result = 0;
	}
	else if (index == 1)
	{
		result = 1;
	}
	else if (index > 1)
	{
		result = getItemInFibonacciWithIndex(index - 1) + getItemInFibonacciWithIndex(index - 2);
	}
	else
	{
		std::cout << "index error!\n";
		result = -1;
	}
	return result;
}

float getSqrt(int num) {
	float temp = 0.0f;
	temp = (float)num;
	double res = 0.0001;
	if (num < 0)
	{
		temp = -1;
		std::cout << "num error!\n";
	}
	else
	do
	{
		temp = (temp*temp + num) / (2 * temp);
	}
	while (temp*temp > num+ res);
	return temp;
}

int main(int argc, const char * argv[]) {
	int result1 = getItemInFibonacciWithIndex(-1);
	float result2 = getSqrt(-1);
	if (result1 >= 0)
	{
		std::cout << result1 << std::endl;
	}
	if (result2 >= 0)
	{
		std::cout << result2 << std::endl;
	}
	return 0;
}